﻿///***************************************************************
/// 시  스  템 : Updms.Batch
/// 단위시스템 : iPhone
/// 계      층 : Batch
/// 프로그램명 : Updms.Batch.iPhone
/// 파  일  명 : Program.cs
/// 설      명 : 배치로 아이폰 조회파일(HTML)을 생성하여 FTP서버로 전송
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2012-07-12 송시명   최초 작성
///***************************************************************
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.EnterpriseServices;
using System.IO;
using System.Linq;
using System.Text;

using SMFramework.Adapter;
using SMFramework.Security;
using SMFramework.Utility;
using SMFramework.Data;
using SMFramework.Diagnostics;

using Updms.Crd.Dac;
using Updms.Mny.Dac;


namespace Updms.Batch.iPhone
{
	public class Program
	{
		#region 전역변수
		private static string FTP_HOSTNAME = ConfigurationManager.AppSettings.Get("Ftp.HostName");
		private static string FTP_USERID = ConfigurationManager.AppSettings.Get("Ftp.UserId");
		private static string FTP_PASSWORD = ConfigurationManager.AppSettings.Get("Ftp.Password");
		private static string FTP_DIR_IPHONE_CRD = ConfigurationManager.AppSettings.Get("Ftp.Dir.Iphone.Crd");
		private static string FTP_DIR_IPHONE_MNY = ConfigurationManager.AppSettings.Get("Ftp.Dir.Iphone.Mny");
		private static string FILE_PATH_FTP_UPLOAD = ConfigurationManager.AppSettings.Get("FilePath.Ftp.Upload");

		//변수(공통)
		private static string TARGET_PROGRAM_ID = ConfigurationManager.AppSettings.Get("Target.Program.Id");
		private static string CURRENT_YEAR = ConfigurationManager.AppSettings.Get("Current.Year");
		private static string LANG_SET = ConfigurationManager.AppSettings.Get("Lang.Set");

		//변수(카드)
		private static string CARD_CD = ConfigurationManager.AppSettings.Get("Card.Cd");
		private static string CARD_NM = ConfigurationManager.AppSettings.Get("Card.Nm");

		private static string[] ga_card_cd = CARD_CD.Split(',');
		private static string[] ga_card_nm = CARD_NM.Split(',');
		
		#endregion

		static void Main(string[] args)
		{
			SendHtml();
		}

		#region SendHtml
		//분기처리
		private static void SendHtml()
		{
			try
			{
				string [] pids = TARGET_PROGRAM_ID.Split(',');
				if (pids.Length > 0)
				{
					for (int i = 0; i < pids.Length; i++)
					{
						GetData(pids[i]);
					}
				}
			}
			catch(Exception ex)
			{
				Log.WriteLogFile("데이터 생성 오류", "SendHtml()", ex.Message);
			}
		}
		#endregion

		#region GetData - 분기
		private static void GetData(string pid)
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			string dir = "";
			string title = "";
			string tableName = "";
			CURRENT_YEAR = (CURRENT_YEAR == "") ? DateTime.Today.Year.ToString() : CURRENT_YEAR;

			switch (pid)
			{
				case "Crd1011m":	//카드결제일관리
					#region Crd1011m
					lo_dp.AddProperty("ls_card_cd", typeof(string));
					lo_dp.AddProperty("li_st_page", typeof(Int32), 0);
					lo_dp.AddProperty("li_ed_page", typeof(Int32), 12);

					if (ga_card_cd.Length > 0)
					{
						for (int i = 0; i < ga_card_cd.Length; i++)
						{
							string subTitle = "<div class=\"sub_title\">";
							string cardCd = ga_card_cd[i];
							string cardNm = ga_card_nm[i];

							lo_dp["ls_card_cd"] = cardCd;

							Crd_Dac_UPDMS_CRD_PAYMNT_DT _Crd1011m = new Crd_Dac_UPDMS_CRD_PAYMNT_DT();
							lo_ds.Merge(_Crd1011m.SelectProcess(lo_dp));

							tableName = "UPDMS_CRD_PAYMNT_DT";
							dir = FTP_DIR_IPHONE_CRD;

							title = "카드결제일 (" + ga_card_nm[i] + ")";

							//서브타이틀 생성
							for (int j = 0; j < ga_card_cd.Length; j++)
							{
								string cardCdSubTitle = ga_card_cd[j];
								string cardNmSubTitle = ga_card_nm[j];
								string cls = (cardCd == cardCdSubTitle) ? "crd" : "crd not_selected";
								string imgLink = pid + "_" + cardCdSubTitle + ".html";
								string imgSrc = "<img src=\"../image/" + cardCdSubTitle + ".gif\"" + " class=\"" + cls + "\" alt=\"" + cardNmSubTitle + "\" />";

								subTitle += "<a href=\"" + imgLink + "\" target=\"main\">" + imgSrc + "</a>";
							}
							subTitle = subTitle + "</div>";

							UploadFtpHtmlFile(pid, lo_ds, dir, title, subTitle, tableName, pid + "_" + cardCd + ".html");

							lo_ds.Clear();
						}
					}
					#endregion
					break;
				case "Crd2010r":	//카드명세서
					#region Crd2010r
					lo_dp.AddProperty("ls_card_cd", typeof(string));
					lo_dp.AddProperty("ls_paymnt_dt", typeof(string), "");
					lo_dp.AddProperty("ls_exc_sys_id", typeof(string), "");
					lo_dp.AddProperty("ls_exc_prefix", typeof(string), "");
					lo_dp.AddProperty("ls_order_by", typeof(string), "Account");//결제일자별(Biz_Dt), 사용계정별(Account), 결제금액별(Amount DESC)
					lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);
					
					if (ga_card_cd.Length > 0)
					{
						for (int i = 0; i < ga_card_cd.Length; i++)
						{
							string subTitle = "<div class=\"sub_title\">";
							string cardCd = ga_card_cd[i];
							string cardNm = ga_card_nm[i];

							lo_dp["ls_card_cd"] = cardCd;

							Crd_Dac_UPDMS_CRD_REPORT_Crd2010r _Crd2010r = new Crd_Dac_UPDMS_CRD_REPORT_Crd2010r();
							lo_ds.Merge(_Crd2010r.SelectProcess(lo_dp));

							tableName = "UPDMS_CRD_REPORT";
							dir = FTP_DIR_IPHONE_CRD;

							string paymntDt = DataSetUtil.GetFldStr(lo_ds, tableName, 0, "Paymnt_Dt");
													
							title = "카드명세서 (" + ga_card_nm[i] + ", " + paymntDt + ")";

							//서브타이틀 생성
							for (int j = 0; j < ga_card_cd.Length; j++)
							{
								string cardCdSubTitle = ga_card_cd[j];
								string cardNmSubTitle = ga_card_nm[j];
								string cls = (cardCd == cardCdSubTitle) ? "crd" : "crd not_selected";
								string imgLink = pid + "_" + cardCdSubTitle + ".html";
								string imgSrc = "<img src=\"../image/" + cardCdSubTitle + ".gif\"" + " class=\"" + cls + "\" alt=\"" + cardNmSubTitle + "\" />";

								subTitle += "<a href=\"" + imgLink + "\" target=\"main\">" + imgSrc + "</a>";
							}
							subTitle = subTitle + "</div>";

							UploadFtpHtmlFile(pid, lo_ds, dir, title, subTitle, tableName, pid + "_" + cardCd + ".html");

							lo_ds.Clear();
						}
					}
					#endregion
				break;
				case "Crd2018r":	//연간사용분석표
					#region Crd2018r
					lo_dp.AddProperty("ls_card_cd", typeof(string), CARD_CD);
					lo_dp.AddProperty("ls_base_year", typeof(string), CURRENT_YEAR);
					lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

					Crd_Dac_UPDMS_CRD_REPORT_Crd2018r _Crd2018r_NT = new Crd_Dac_UPDMS_CRD_REPORT_Crd2018r();
					lo_ds.Merge(_Crd2018r_NT.GetYearlyUsingAnalysisList(lo_dp));

					dir = FTP_DIR_IPHONE_CRD;
					title = "연간사용분석표 (" + CURRENT_YEAR + ")";
					tableName = "UPDMS_CRD_REPORT";
					#endregion
				break;
				case "Crd3010p":	//카드대쉬보드
					#region Crd3010p
					Crd_Dac_UPDMS_CRD_REPORT_Crd3010p _Crd3010p_NT = new Crd_Dac_UPDMS_CRD_REPORT_Crd3010p();
					lo_ds.Merge(_Crd3010p_NT.GetImportantItemList());

					dir = FTP_DIR_IPHONE_CRD;
					title = "카드대쉬보드";
					tableName = "UPDMS_CRD_REPORT";
					#endregion
				break;
				case "Crd3013p":	//월간사용분석표
					#region Crd3013p
					string currYm = DateUtil.GetNow("yyyy-MM");
					lo_dp.AddProperty("ls_card_cd", typeof(string), CARD_CD);
					lo_dp.AddProperty("ls_pre_month", typeof(string), DateUtil.GetCalcMonth(currYm, -1, "yyyy-MM"));
					lo_dp.AddProperty("ls_this_month", typeof(string), currYm);
					lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

					Crd_Dac_UPDMS_CRD_REPORT_Crd3013p _Crd3013p = new Crd_Dac_UPDMS_CRD_REPORT_Crd3013p();
					lo_ds.Merge(_Crd3013p.GetIncDecAmountByAccountFromPreMonth(lo_dp));

					dir = FTP_DIR_IPHONE_CRD;
					title = "월간사용분석표 (" + currYm + ")";
					tableName = "UPDMS_CRD_REPORT";
					#endregion
				break;
				case "Mny1010m":	//은행계좌관리
					#region Mny1010m
					lo_dp.AddProperty("ls_accnt_nm", typeof(string), "");
					lo_dp.AddProperty("ls_accnt_num", typeof(string), "");
					lo_dp.AddProperty("ls_depositor", typeof(string), "");
					lo_dp.AddProperty("ls_use_yn", typeof(string), "Y");
					lo_dp.AddProperty("li_st_page", typeof(Int32), 0);
					lo_dp.AddProperty("li_ed_page", typeof(Int32), 1000);
					lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

					Mny_Dac_UPDMS_MNY_BNK_ACCNT_INFO _Mny1010m = new Mny_Dac_UPDMS_MNY_BNK_ACCNT_INFO();
					lo_ds.Merge(_Mny1010m.SelectProcess(lo_dp));

					dir = FTP_DIR_IPHONE_MNY;
					title = "은행계좌관리";
					tableName = "UPDMS_MNY_BNK_ACCNT_INFO";
					#endregion
				break;
				case "Mny2011r":	//연간출납분석표
					#region Mny2011r
					lo_dp.AddProperty("ls_base_year", typeof(string), CURRENT_YEAR);
					lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

					Mny_Dac_UPDMS_MNY_REPORT_Mny2011r _Mny2011r = new Mny_Dac_UPDMS_MNY_REPORT_Mny2011r();
					lo_ds.Merge(_Mny2011r.GetYearlyInOutAnalysisList(lo_dp));

					dir = FTP_DIR_IPHONE_MNY;
					title = "연간출납분석표 (" + CURRENT_YEAR + ")";
					tableName = "UPDMS_MNY_REPORT";
					#endregion
				break;
			}

			if (pid != "Crd2010r") //카드명세서는 case문에서 생성/전송함
			{
				UploadFtpHtmlFile(pid, lo_ds, dir, title, "", tableName, pid + ".html");
			}
		}

		#endregion

		#region UploadFtpHtmlFile
		//넘겨받은 DataSet으로 HTML파일을 만들어 FTP서버로 업로드
		private static void UploadFtpHtmlFile(string pid, DataSet lo_ds, string dir, string title, string subTitle, string tableName, string fileName)
		{
			Crypto crypto = new Crypto();
			FtpClient fc = new FtpClient(FTP_HOSTNAME, FTP_USERID, crypto.Decrypt(FTP_PASSWORD));

			try
			{
				//파일생성
				CreateFileAtDataSet(pid, lo_ds, title, subTitle, tableName, fileName);

				//FTP전송
				if (FileUtil.IsFileExist(FILE_PATH_FTP_UPLOAD + "\\" + fileName))
				{
					fc.Login();
					fc.BinaryMode = false;

					string[] remoteDir = StringUtil.DelimitedListToStringArray(dir, "/");
					for (int i = 0; i < remoteDir.Length; i++)
					{
						fc.ChangeDir(remoteDir[i]);
					}

					if (fc.IsFileExist(fileName))
					{
						fc.DeleteFile(fileName);
					}

					fc.UploadOnlyFile(FILE_PATH_FTP_UPLOAD, fileName, "", "", true);
					fc.Close();

					Log.WriteLogFile(fileName + "(" + title + ") upload ok");
				}
				else
				{
					Log.WriteLogFile("FTP 업로드 error", fileName + "(" + title + ")", "전송할 파일이 없습니다");
				}
			}
			catch (Exception ex)
			{
				Log.WriteLogFile("FTP 업로드 error", fileName + "(" + title + ")", ex.Message);
			}
			finally
			{
				fc.Close();
			}
		}

		#endregion

		#region CreateFileAtDataSet - 분기
		//DataSet에서 HTML파일생성
		private static void CreateFileAtDataSet(string pid, DataSet ds, string title, string subTitle, string tableName, string fileName)
		{
			try
			{
				string ls_stream = FILE_PATH_FTP_UPLOAD + "\\" + fileName;
				FileInfo file = new FileInfo(ls_stream);

				StreamWriter sw = file.CreateText();

				sw.WriteLine(GetDefaultHtmlTag(pid, title, false));

				switch (pid)
				{
					case "Crd1011m":	//카드결제일관리
						#region Crd1011m
						sw.WriteLine(subTitle);
						sw.WriteLine("<table id=\"report_table\" class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>결제일</th>");
						sw.WriteLine("<th>요일</th>");
						sw.WriteLine("<th>시작일 (일시불,할부)</th>");
						sw.WriteLine("<th>종료일 (일시불,할부)</th>");
						sw.WriteLine("<th>시작일 (현금서비스)</th>");
						sw.WriteLine("<th>종료일 (현금서비스)</th>");
						sw.WriteLine("</tr>");

						for (int i = 0; i < DataSetUtil.GetRowCount(ds, tableName); i++)
						{
							string paymntDt = DataSetUtil.GetFldStr(ds, tableName, i, "Paymnt_Dt");
							string weekOfDay = DataSetUtil.GetFldStr(ds, tableName, i, "Week_Of_Day");
							string massStDt = DataSetUtil.GetFldStr(ds, tableName, i, "Mass_St_Dt");
							string massEdDt = DataSetUtil.GetFldStr(ds, tableName, i, "Mass_Ed_Dt");
							string cashStDt = DataSetUtil.GetFldStr(ds, tableName, i, "Cash_St_Dt");
							string cashEdDt = DataSetUtil.GetFldStr(ds, tableName, i, "Cash_Ed_Dt");

							sw.WriteLine("<td class=\"lbl_c\">" + paymntDt + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + weekOfDay + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + massStDt + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + massEdDt + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + cashStDt + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + cashEdDt + "</td>");
				
							sw.WriteLine("</tr>");
						}
						sw.WriteLine("</table>");
						#endregion
					break;
					case "Crd2010r":	//카드명세서
						#region Crd2010r

						sw.WriteLine(subTitle);
						sw.WriteLine("<table id=\"report_table\" class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>결제일</th>");
						sw.WriteLine("<th>결제구분</th>");
						sw.WriteLine("<th>계정</th>");
						sw.WriteLine("<th>결제내용</th>");
						sw.WriteLine("<th>상세내용</th>");
						sw.WriteLine("<th>당월금액</th>");
						sw.WriteLine("</tr>");
						for (int i = 0; i < DataSetUtil.GetRowCount(ds, tableName); i++)
						{
							string bizDt = DataSetUtil.GetFldStr(ds, tableName, i, "Biz_Dt");
							string bizDiv = DataSetUtil.GetFldStr(ds, tableName, i, "Biz_Div");
							string bizDivNm = DataSetUtil.GetFldStr(ds, tableName, i, "Biz_Div_Nm");
							string accountNm = DataSetUtil.GetFldStr(ds, tableName, i, "Account_Nm");
							string contents = DataSetUtil.GetFldStr(ds, tableName, i, "Contents");
							string realRemark = DataSetUtil.GetFldStr(ds, tableName, i, "Real_Remark");
							int amount = DataSetUtil.GetFldInt(ds, tableName, i, "Amount");

							//소계, 총계
							if (bizDiv == "BA001" || bizDiv == "BA002" || bizDiv == "BA003")
							{
								sw.WriteLine("<tr class=\"sub_total\">");
							}
							else if (bizDiv == "BB006")
							{
								sw.WriteLine("<tr class=\"total\">");
							}
							else
							{
								sw.WriteLine("<tr>");
							}

							sw.WriteLine("<td class=\"lbl_c\">" + bizDt + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + bizDivNm + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + accountNm + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + contents + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + realRemark + "</td>");
							sw.WriteLine("<td class=\"data\">" + amount.ToString("#,###,##0") + "</td>");
				
							sw.WriteLine("</tr>");
						}
						sw.WriteLine("</table>");
						sw.WriteLine("<script type=\"text/javascript\" language=\"javascript\" defer=\"defer\">");
						sw.WriteLine("TableRowspan(report_table, '1');TableRowspan(report_table, '1');");
						sw.WriteLine("</script>");

						#endregion
					break;
					case "Crd2018r":	//연간사용분석표
						#region Crd2018r
						sw.WriteLine("<table class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>계정</th>");
						sw.WriteLine("<th>1월</th>");
						sw.WriteLine("<th>2월</th>");
						sw.WriteLine("<th>3월</th>");
						sw.WriteLine("<th>4월</th>");
						sw.WriteLine("<th>5월</th>");
						sw.WriteLine("<th>6월</th>");
						sw.WriteLine("<th>7월</th>");
						sw.WriteLine("<th>8월</th>");
						sw.WriteLine("<th>9월</th>");
						sw.WriteLine("<th>10월</th>");
						sw.WriteLine("<th>11월</th>");
						sw.WriteLine("<th>12월</th>");
						sw.WriteLine("<th>총액</th>");
						sw.WriteLine("</tr>");

						for (int i = 0; i < DataSetUtil.GetRowCount(ds, tableName); i++)
						{
							string accountNm = DataSetUtil.GetFldStr(ds, tableName, i, "Account_Nm");
							int m01 = DataSetUtil.GetFldInt(ds, tableName, i, "M01");
							int m02 = DataSetUtil.GetFldInt(ds, tableName, i, "M02");
							int m03 = DataSetUtil.GetFldInt(ds, tableName, i, "M03");
							int m04 = DataSetUtil.GetFldInt(ds, tableName, i, "M04");
							int m05 = DataSetUtil.GetFldInt(ds, tableName, i, "M05");
							int m06 = DataSetUtil.GetFldInt(ds, tableName, i, "M06");
							int m07 = DataSetUtil.GetFldInt(ds, tableName, i, "M07");
							int m08 = DataSetUtil.GetFldInt(ds, tableName, i, "M08");
							int m09 = DataSetUtil.GetFldInt(ds, tableName, i, "M09");
							int m10 = DataSetUtil.GetFldInt(ds, tableName, i, "M10");
							int m11 = DataSetUtil.GetFldInt(ds, tableName, i, "M11");
							int m12 = DataSetUtil.GetFldInt(ds, tableName, i, "M12");
							int totalAmt = DataSetUtil.GetFldInt(ds, tableName, i, "Total_Amt");

							//총계
							if (i < DataSetUtil.GetRowCount(ds, tableName) - 1)
							{
								sw.WriteLine("<tr>");
							}
							else
							{
								sw.WriteLine("<tr class=\"total\">");
							}
							sw.WriteLine("<td class=\"lbl\">" + accountNm + "</td>");
							sw.WriteLine("<td class=\"data\">" + m01.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m02.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m03.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m04.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m05.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m06.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m07.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m08.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m09.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m10.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m11.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m12.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"total_amt\">" + totalAmt.ToString("#,###,##0") + "</td>");
							sw.WriteLine("</tr>");
						}
						sw.WriteLine("</table>");

						#endregion
					break;
					case "Crd3010p":	//카드대쉬보드
						#region Crd3010p
						sw.WriteLine("<table id=\"report_table\" class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>내용</th>");
						sw.WriteLine("<th>경과일</th>");
						sw.WriteLine("<th>결제일</th>");
						sw.WriteLine("<th>비고</th>");
						sw.WriteLine("<th>금액</th>");
						sw.WriteLine("</tr>");

						for (int i = 0; i < DataSetUtil.GetRowCount(ds, tableName); i++)
						{
							string contents = DataSetUtil.GetFldStr(ds, tableName, i, "Contents");
							string cnt = DataSetUtil.GetFldStr(ds, tableName, i, "Cnt");
							string bizDt = DataSetUtil.GetFldStr(ds, tableName, i, "Biz_Dt");
							string remark = DataSetUtil.GetFldStr(ds, tableName, i, "Remark");
							string amount = DataSetUtil.GetFldStr(ds, tableName, i, "Amount");

							sw.WriteLine("<tr>");
							sw.WriteLine("<td class=\"lbl\">" + contents + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + cnt + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + bizDt + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + remark + "</td>");
							sw.WriteLine("<td class=\"data\">" + amount + "</td>");
							sw.WriteLine("</tr>");
						}
						sw.WriteLine("</table>");
						sw.WriteLine("<script type=\"text/javascript\" language=\"javascript\" defer=\"defer\">");
						sw.WriteLine("TableRowspan(report_table, '0');");
						sw.WriteLine("</script>");
						#endregion
					break;
					case "Crd3013p":	//월간사용분석표
						#region Crd3013p
						int preTotalTemp = 0;
						int thisTotalTemp = 0;
						int diffTotalTemp = 0;

						sw.WriteLine("<table class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>계정</th>");
						sw.WriteLine("<th>전월</th>");
						sw.WriteLine("<th>당월</th>");
						sw.WriteLine("<th>증감액</th>");
						sw.WriteLine("</tr>");
						for (int i = 0; i < DataSetUtil.GetRowCount(ds, tableName); i++)
						{
							string accountNm = DataSetUtil.GetFldStr(ds, tableName, i, "Account_Nm");
							int preTotal = DataSetUtil.GetFldInt(ds, tableName, i, "Pre_Total");
							int thisTotal = DataSetUtil.GetFldInt(ds, tableName, i, "This_Total");
							int diffTotal = DataSetUtil.GetFldInt(ds, tableName, i, "Diff_Total");

							preTotalTemp += preTotal;
							thisTotalTemp += thisTotal;
							diffTotalTemp += diffTotal;

							string cls = (diffTotal < 0) ? "color_blue" : "color_darkred";

							sw.WriteLine("<td class=\"lbl\">" + accountNm + "</td>");
							sw.WriteLine("<td class=\"data\">" + preTotal.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + thisTotal.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data " + cls + "\">" + diffTotal.ToString("#,###,##0") + "</td>");
							sw.WriteLine("</tr>");
						}
						//총계
						sw.WriteLine("<tr class=\"total\">");
						sw.WriteLine("<td class=\"lbl\">총계</td>");
						sw.WriteLine("<td class=\"data\">" + preTotalTemp.ToString("#,###,##0") + "</td>");
						sw.WriteLine("<td class=\"data\">" + thisTotalTemp.ToString("#,###,##0") + "</td>");
						sw.WriteLine("<td class=\"data\">" + diffTotalTemp.ToString("#,###,##0") + "</td>");
						sw.WriteLine("</tr>");
						sw.WriteLine("</table>");
						#endregion
					break;
					case "Mny1010m":	//은행계좌관리
						#region Mny1010m
						sw.WriteLine("<table id=\"report_table\" class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>은행</th>");
						sw.WriteLine("<th>계좌명</th>");
						sw.WriteLine("<th>계좌번호</th>");
						sw.WriteLine("<th>예금주</th>");
						sw.WriteLine("<th>계좌개설일</th>");
						sw.WriteLine("<th>사용여부</th>");
						sw.WriteLine("</tr>");

						int rCount = DataSetUtil.GetRowCount(ds, tableName);
						for (int i = 0; i < rCount; i++)
						{
							string bnkCdNm = DataSetUtil.GetFldStr(ds, tableName, i, "Bnk_Cd_Nm");
							string accntNm = DataSetUtil.GetFldStr(ds, tableName, i, "Accnt_Nm");
							string accntNum = DataSetUtil.GetFldStr(ds, tableName, i, "Accnt_Num");
							string depositor = DataSetUtil.GetFldStr(ds, tableName, i, "Depositor");
							string accntStDt = DataSetUtil.GetFldStr(ds, tableName, i, "Accnt_St_Dt");
							string useYn = DataSetUtil.GetFldStr(ds, tableName, i, "Use_Yn");

							sw.WriteLine("<tr>");
							sw.WriteLine("<td class=\"lbl\">" + bnkCdNm + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + accntNm + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + accntNum + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + depositor + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + accntStDt + "</td>");
							sw.WriteLine("<td class=\"lbl_c\">" + useYn + "</td>");
							sw.WriteLine("</tr>");
						}
						sw.WriteLine("</table>");
						sw.WriteLine("<script type=\"text/javascript\" language=\"javascript\" defer=\"defer\">");
						sw.WriteLine("TableRowspan(report_table, '0');");
						sw.WriteLine("</script>");
						#endregion
					break;
					case "Mny2011r":	//연간출납분석표
						#region Mny2011r
						sw.WriteLine("<table class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>계정</th>");
						sw.WriteLine("<th>1월</th>");
						sw.WriteLine("<th>2월</th>");
						sw.WriteLine("<th>3월</th>");
						sw.WriteLine("<th>4월</th>");
						sw.WriteLine("<th>5월</th>");
						sw.WriteLine("<th>6월</th>");
						sw.WriteLine("<th>7월</th>");
						sw.WriteLine("<th>8월</th>");
						sw.WriteLine("<th>9월</th>");
						sw.WriteLine("<th>10월</th>");
						sw.WriteLine("<th>11월</th>");
						sw.WriteLine("<th>12월</th>");
						sw.WriteLine("<th>총액</th>");
						sw.WriteLine("</tr>");

						for (int i = 0; i < DataSetUtil.GetRowCount(ds, tableName); i++)
						{
							string viewOrder = DataSetUtil.GetFldStr(ds, tableName, i, "view_Order");
							string accountNm = DataSetUtil.GetFldStr(ds, tableName, i, "Account_Nm");
							double m01 = DataSetUtil.GetFldDbl(ds, tableName, i, "M01");
							double m02 = DataSetUtil.GetFldDbl(ds, tableName, i, "M02");
							double m03 = DataSetUtil.GetFldDbl(ds, tableName, i, "M03");
							double m04 = DataSetUtil.GetFldDbl(ds, tableName, i, "M04");
							double m05 = DataSetUtil.GetFldDbl(ds, tableName, i, "M05");
							double m06 = DataSetUtil.GetFldDbl(ds, tableName, i, "M06");
							double m07 = DataSetUtil.GetFldDbl(ds, tableName, i, "M07");
							double m08 = DataSetUtil.GetFldDbl(ds, tableName, i, "M08");
							double m09 = DataSetUtil.GetFldDbl(ds, tableName, i, "M09");
							double m10 = DataSetUtil.GetFldDbl(ds, tableName, i, "M10");
							double m11 = DataSetUtil.GetFldDbl(ds, tableName, i, "M11");
							double m12 = DataSetUtil.GetFldDbl(ds, tableName, i, "M12");
							double totalAmt = DataSetUtil.GetFldDbl(ds, tableName, i, "Total_Amt");

							//소계, 총계
							if (viewOrder == "AA001T" || viewOrder == "AA002T" || viewOrder == "AA003T")
							{
								sw.WriteLine("<tr class=\"sub_total\">");
							}
							else if (viewOrder == "AA004T")
							{
								sw.WriteLine("<tr class=\"total\">");
							}
							else
							{
								sw.WriteLine("<tr>");
							}

							sw.WriteLine("<td class=\"lbl\">" + accountNm + "</td>");
							sw.WriteLine("<td class=\"data\">" + m01.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m02.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m03.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m04.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m05.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m06.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m07.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m08.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m09.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m10.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m11.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"data\">" + m12.ToString("#,###,##0") + "</td>");
							sw.WriteLine("<td class=\"total_amt\">" + totalAmt.ToString("#,###,##0") + "</td>");
							sw.WriteLine("</tr>");
						}
						sw.WriteLine("</table>");
						#endregion
					break;
					case "Mny2018r":	//월별예산대비지출 - 구현중(2012.07.31)
						#region Mny2018r
						//수입
						sw.WriteLine("<table class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>구분</th>");
						sw.WriteLine("<th>등록일</th>");
						sw.WriteLine("<th>계정</th>");
						sw.WriteLine("<th>내용</th>");
						sw.WriteLine("<th>금액</th>");
						sw.WriteLine("<th>비고</th>");
						sw.WriteLine("<th>합계</th>");
						sw.WriteLine("</tr>");

						int rCountIn = DataSetUtil.GetRowCount(ds, tableName);
						for (int i = 0; i < rCountIn; i++)
						{
							string regDt = DataSetUtil.GetFldStr(ds, tableName, i, "Reg_Dt");
							string accountNm = DataSetUtil.GetFldStr(ds, tableName, i, "Account_Nm");
							string contents = DataSetUtil.GetFldStr(ds, tableName, i, "Contents");
							string amount = ConversionUtil.AddComma(DataSetUtil.GetFldStr(ds, tableName, i, "Amount"));
							string remark = DataSetUtil.GetFldStr(ds, tableName, i, "Remark");
							string totalAmt = ConversionUtil.AddComma(DataSetUtil.GetFldStr(ds, tableName, i, "Total_Amt"));

							sw.WriteLine("<tr>");
							//구분 rowspan
							if (i == 0)
							{
								sw.WriteLine("<td class=\"lbl_c\" rowspan=\"" + rCountIn + "\">수입</td>");
							}
							sw.WriteLine("<td class=\"lbl_c\">" + regDt + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + accountNm + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + contents + "</td>");
							sw.WriteLine("<td class=\"data\">" + amount + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + remark + "</td>");

							if (i == 0)
							{
								sw.WriteLine("<td class=\"lbl_c b\" rowspan=\"" + rCountIn + "\">" + totalAmt + "</td>");
							}
							sw.WriteLine("</tr>");
						}
						sw.WriteLine("</table>");

						sw.WriteLine("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<td>");
						//예산대비지출
						sw.WriteLine("<table id=\"report_table\" class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<th>구분</th>");
						sw.WriteLine("<th>계정</th>");
						sw.WriteLine("<th>예산</th>");
						sw.WriteLine("<th>나간돈</th>");
						sw.WriteLine("<th>남은돈</th>");
						sw.WriteLine("</tr>");

						int rCountBudget = DataSetUtil.GetRowCount(ds, tableName);
						int tBudget = 0;	//합계
						int tOutAmount = 0;	//합계
						int tBalanceAmount = 0;	//합계

						for (int i = 0; i < rCountBudget; i++)
						{
							string classNm = DataSetUtil.GetFldStr(ds, tableName, i, "Class_Nm");
							string accountNm = DataSetUtil.GetFldStr(ds, tableName, i, "Account_Nm");

							int iBudget = DataSetUtil.GetFldInt(ds, tableName, i, "Budget");
							int iOutAmount = DataSetUtil.GetFldInt(ds, tableName, i, "Out_Amount");
							int iBalanceAmount = DataSetUtil.GetFldInt(ds, tableName, i, "Balance_Amount");

							tBudget += iBudget;
							tOutAmount += iOutAmount;
							tBalanceAmount += iBalanceAmount;

							string budget = ConversionUtil.AddComma(iBudget.ToString());
							string outAmount = ConversionUtil.AddComma(iOutAmount.ToString());
							string balanceAmount = ConversionUtil.AddComma(iBalanceAmount.ToString());

							sw.WriteLine("<tr>");
							sw.WriteLine("<td class=\"lbl_c\">" + classNm + "</td>");
							sw.WriteLine("<td class=\"lbl\">" + accountNm + "</td>");
							sw.WriteLine("<td class=\"data\">" + budget + "</td>");
							sw.WriteLine("<td class=\"data\">" + outAmount + "</td>");
							sw.WriteLine("<td class=\"data\">" + balanceAmount + "</td>");
							sw.WriteLine("</tr>");
						}
						sw.WriteLine("<tr class=\"total\">");
						sw.WriteLine("<td class=\"lbl_c\" colspan=\"2\">Total</td>");
						sw.WriteLine("<td class=\"data\">" + ConversionUtil.AddComma(tBudget.ToString()) + "</td>");
						sw.WriteLine("<td class=\"data\">" + ConversionUtil.AddComma(tOutAmount.ToString()) + "</td>");
						sw.WriteLine("<td class=\"data\">" + ConversionUtil.AddComma(tBalanceAmount.ToString()) + "</td>");
						sw.WriteLine("</table>");
						sw.WriteLine("</td>");
						sw.WriteLine("<td valign=\"top\">");
						sw.WriteLine("<table class=\"report\">");
						sw.WriteLine("<tr>");
						sw.WriteLine("<td style=\"padding:28px 0 0 0;\">");
						sw.WriteLine("<img src=\"" + pid + ".png" + "\" width=\"471\" height=\"1021\" />");
						sw.WriteLine("</td>");
						sw.WriteLine("</tr>");
						sw.WriteLine("</table>");
						sw.WriteLine("</tr>");
						sw.WriteLine("</table>");
						sw.WriteLine("<script type=\"text/javascript\" language=\"javascript\" defer=\"defer\">");
						sw.WriteLine("TableRowspan(report_table, '0');");
						sw.WriteLine("</script>");
						#endregion
					break;
				}

				sw.WriteLine("</body>");
				sw.WriteLine("</html>");

				sw.Close();

				Log.WriteLogFile(fileName + "(" + title + ") file create ok");
			}
			catch (Exception ex)
			{
				Log.WriteLogFile("DataSet에서 HTML파일생성시 error", "CreateFileAtDataSet", ex.Message);
			}
		}
		#endregion
		
		#region 기본으로 생성되어야 하는 HTML Tag

		public static string GetDefaultHtmlTag(string pid, string pgmNm, bool isLink)
		{
			StringBuilder sb = new StringBuilder();
			sb.AppendLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
			sb.AppendLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
			sb.AppendLine("<head><title></title>");
			sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
			sb.AppendLine("<link href=\"../default.css?ver=1\" type=\"text/css\" rel=\"stylesheet\" />");
			sb.AppendLine("<script type=\"text/javascript\" language=\"javascript\" src=\"../default.js\"></script>");

			sb.AppendLine("</head>");
			sb.AppendLine("<body>");

			if (isLink)
			{
				sb.AppendLine("<div class=\"title\"><a href=\"" + pid + ".html" + "\" target=\"main\">" + pgmNm + "</a></div>");
			}
			else
			{
				sb.AppendLine("<div class=\"title\">" + pgmNm + "</div>");
			}

			string createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
			sb.AppendLine("<div class=\"currTime\">" + createTime + "</div>");

			return sb.ToString();
		}

		#endregion
	}
}
